/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package entidade.persistencia;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 *
 * @author victorinox
 */
@Entity
@Table(name = "tipo_usuario")
@NamedQueries({@NamedQuery(name = "TipoUsuario.findAll", query = "SELECT t FROM TipoUsuario t"), @NamedQuery(name = "TipoUsuario.findByTipoUsuarioId", query = "SELECT t FROM TipoUsuario t WHERE t.tipoUsuarioId = :tipoUsuarioId"), @NamedQuery(name = "TipoUsuario.findByNome", query = "SELECT t FROM TipoUsuario t WHERE t.nome = :nome")})
public class TipoUsuario implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "tipo_usuario_id")
    private Integer tipoUsuarioId;
    @Basic(optional = false)
    @Column(name = "nome")
    private String nome;
    @ManyToMany(mappedBy = "tipoUsuarioCollection", fetch = FetchType.LAZY)
    private List<Permissao> permissaoCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "tipoUsuarioId", fetch = FetchType.LAZY)
    private List<Usuario> usuarioCollection;
    @JoinColumn(name = "vinculo_id", referencedColumnName = "vinculo_id")
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Vinculo vinculoId;

    public TipoUsuario() {
    }

    public TipoUsuario(Integer tipoUsuarioId) {
        this.tipoUsuarioId = tipoUsuarioId;
    }

    public TipoUsuario(Integer tipoUsuarioId, String nome) {
        this.tipoUsuarioId = tipoUsuarioId;
        this.nome = nome;
    }

    public Integer getTipoUsuarioId() {
        return tipoUsuarioId;
    }

    public void setTipoUsuarioId(Integer tipoUsuarioId) {
        this.tipoUsuarioId = tipoUsuarioId;
    }

    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

    public List<Permissao> getPermissaoCollection() {
        return permissaoCollection;
    }

    public void setPermissaoCollection(List<Permissao> permissaoCollection) {
        this.permissaoCollection = permissaoCollection;
    }

    public List<Usuario> getUsuarioCollection() {
        return usuarioCollection;
    }

    public void setUsuarioCollection(List<Usuario> usuarioCollection) {
        this.usuarioCollection = usuarioCollection;
    }

    public Vinculo getVinculoId() {
        return vinculoId;
    }

    public void setVinculoId(Vinculo vinculoId) {
        this.vinculoId = vinculoId;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (tipoUsuarioId != null ? tipoUsuarioId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof TipoUsuario)) {
            return false;
        }
        TipoUsuario other = (TipoUsuario) object;
        if ((this.tipoUsuarioId == null && other.tipoUsuarioId != null) || (this.tipoUsuarioId != null && !this.tipoUsuarioId.equals(other.tipoUsuarioId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return getNome();
    }

}
